/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.menosehmais.framework.loggin;

import org.apache.log4j.Logger;

/**
 *
 * @author Quintino
 */
public class StackTraceLogger extends LogAble {

    private StackTraceLogger() {
        super();
    }
    
    public static final StackTraceLogger INSTANCE = new StackTraceLogger();
    
    public void printStackTrace(Error e) {
        printStackTrace((Throwable) e, this.getLogger());
    }
    
    public void printStackTrace(Exception e) {
        printStackTrace((Throwable) e, this.getLogger());
    }

    public void printStackTrace(Throwable t) {
        printStackTrace((Throwable) t, this.getLogger());
    }

    public static void printStackTrace(Error e, Logger l) {
        printStackTrace((Throwable) e, l);
    }

    public static void printStackTrace(Exception e, Logger l) {
        printStackTrace((Throwable) e, l);
    }

    public static void printStackTrace(Throwable t, Logger l) {
        StringBuilder strBuilder = new StringBuilder(100);
        StackTraceElement traceElements[] = t.getStackTrace();

        strBuilder.append("Exception: ");
        strBuilder.append(t.getMessage());
        for (StackTraceElement element : traceElements) {
            strBuilder.append("\n\tat ");
            strBuilder.append(element.getClassName());
            strBuilder.append('.');
            strBuilder.append(element.getMethodName());
            strBuilder.append('(');
            strBuilder.append(element.getFileName());
            strBuilder.append(':');
            strBuilder.append(element.getLineNumber());
            strBuilder.append(')');
        }
        l.error(strBuilder.toString());
    }
}
